package com.galo.service.controller;

import com.alibaba.fastjson.JSONObject;
import com.galo.service.common.Result;
import com.galo.service.common.ResultGenerator;
import com.galo.service.service.ElectricCurtainService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 电动窗帘
 * @Auther: lxlin
 * @Date: 2018/11/16 13:09
 * @Description:
 */
@RestController
@RequestMapping("/api/v1/curtain")
public class ElectricCurtainController {

    @Autowired
    private ElectricCurtainService curtainService;

    /**
     * 电动窗帘接口
     * @param body
     * @return
     */
    @PostMapping("/control")
    public Result curtain(@RequestBody String body){
        JSONObject object = JSONObject.parseObject(body);
        String devsn = object.getString("devsn");
        int target = object.getIntValue("target");
        curtainService.curtain(devsn,target);
        return ResultGenerator.genSuccessResult("指令发送成功！");
    }
}
